package net.sf.midollo.net.protocol.tunnel;

import net.sf.midollo.io.IOStream;
import net.sf.midollo.io.IOStreamFactory;
import net.sf.midollo.net.protocol.Protocol;
import net.sf.midollo.net.protocol.ProtocolFactory;

import java.io.IOException;

public class TunnelFactory implements ProtocolFactory {

	public static final int DEFAULT_BUFFER_SIZE = 8 * 1024;

	protected final IOStreamFactory ioStreamFactory;
	protected final int bufSizeRequest;
	protected final int bufSizeResponse;

	public TunnelFactory(IOStreamFactory ioStreamFactory) {
		this(ioStreamFactory, DEFAULT_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
	}

	public TunnelFactory(IOStreamFactory ioStreamFactory, int bufSizeRequest, int bufSizeResponse) {
		this.ioStreamFactory = ioStreamFactory;
		this.bufSizeRequest = bufSizeRequest;
		this.bufSizeResponse = bufSizeResponse;
	}

	public Protocol connect(IOStream ioRequest) throws IOException {
		return new Tunnel(ioRequest, this.ioStreamFactory, this.bufSizeRequest, this.bufSizeResponse);
	}
}
